package com.niuke;

import com.sun.corba.se.impl.oa.toa.TOA;
import org.omg.CORBA.INTERNAL;

import java.util.*;

/**
 * @ClassName : HJ48
 * @Author : kele
 * @Date: 2023/4/8 18:44
 * @Description :
 */
public class HJ48 {

    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);

        while (in.hasNext()) {

            ArrayList<Integer> result = new ArrayList<>();

            int total = in.nextInt();
            int head = in.nextInt();
            result.add(head);

            for (int i = 0; i < total - 1; i++) {
                int bef = in.nextInt();
                int lst = in.nextInt();
                result.add(result.indexOf(lst) + 1, bef);
            }

            int remove = in.nextInt();

            result.remove((Object) remove);

            for (int i : result) {
                System.out.print(i + " ");
            }
            System.out.println();

        }


    }



}
